package com.gimi.cloud.jimi.merchantZone.controller.ueditor;

import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.commonService.ueditor.JimiActionEnter;
import com.gimi.cloud.jimi.commonService.ueditor.UeditorUpload;
import com.gimi.cloud.jimi.commonService.ueditor.imp.UeditorUploadImp;
import com.gimi.cloud.jimi.merchantZone.service.store.StoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Created by wangwei on 2018/2/1.
 */
@RestController
@RequestMapping(value = "ueditor")
public class UeditorController {
    private final StoreService storeService;
    private static Logger logger = LoggerFactory.getLogger(UeditorController.class);

    @Autowired
    public UeditorController(StoreService storeService){
        this.storeService = storeService;
    }



    @RequestMapping(value = "/action")
    public void ueditorAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //获取要处理的类名
        String handleClassName = request.getParameter("handleClassName");
        logger.info("==============>"+handleClassName);
        //构建一个类
        UeditorUpload ueditorUpload = new UeditorUploadImp();
        if(handleClassName!=null && !"".equals(handleClassName)){
            ueditorUpload = (UeditorUpload)Class.forName(handleClassName).newInstance();
        }
        String configPath = request.getParameter("filePath");
        String configFileName = request.getParameter("configFileName");
        logger.info(configPath);
        JimiActionEnter actionEnter = new JimiActionEnter( request, configPath, configFileName, null, ueditorUpload);
        String result = actionEnter.exec();
        logger.info(result);
        Util.sendResponse(result, response);
    }

}
